<template>
  <a-layout class="admin-layout">
    <a-layout-sider
      v-model:collapsed="collapsed"
      :trigger="null"
      collapsible
      theme="dark"
    >
      <div class="logo">
        <h2>{{ collapsed ? '🔐' : '🔐 Admin Panel' }}</h2>
      </div>
      
      <a-menu
        v-model:selectedKeys="selectedKeys"
        theme="dark"
        mode="inline"
      >
        <a-menu-item key="rooms" @click="activeTab = 'rooms'">
          <HomeOutlined />
          <span>会议室管理</span>
        </a-menu-item>
        <a-menu-item key="all-bookings" @click="activeTab = 'all-bookings'">
          <CalendarOutlined />
          <span>所有预定</span>
        </a-menu-item>
        <a-menu-item key="settings" @click="activeTab = 'settings'">
          <SettingOutlined />
          <span>系统设置</span>
        </a-menu-item>
      </a-menu>
    </a-layout-sider>

    <a-layout>
      <a-layout-header class="admin-header">
        <MenuUnfoldOutlined
          v-if="collapsed"
          class="trigger"
          @click="collapsed = !collapsed"
        />
        <MenuFoldOutlined
          v-else
          class="trigger"
          @click="collapsed = !collapsed"
        />
        
        <div class="header-right">
          <span>管理员: <strong>{{ authStore.user?.username }}</strong></span>
          <a-button @click="goToBooking">用户界面</a-button>
          <a-button @click="handleLogout">退出登录</a-button>
        </div>
      </a-layout-header>

      <a-layout-content class="admin-content">
        <room-management v-if="activeTab === 'rooms'" />
        <all-bookings v-if="activeTab === 'all-bookings'" />
        <system-settings v-if="activeTab === 'settings'" />
      </a-layout-content>
    </a-layout>
  </a-layout>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { message } from 'ant-design-vue'
import {
  MenuFoldOutlined,
  MenuUnfoldOutlined,
  HomeOutlined,
  CalendarOutlined,
  SettingOutlined,
} from '@ant-design/icons-vue'
import { useAuthStore } from '@/store/auth'
import RoomManagement from '@/components/RoomManagement.vue'
import AllBookings from '@/components/AllBookings.vue'
import SystemSettings from '@/components/SystemSettings.vue'

const router = useRouter()
const authStore = useAuthStore()

const collapsed = ref(false)
const selectedKeys = ref(['rooms'])
const activeTab = ref('rooms')

const handleLogout = () => {
  authStore.logout()
  message.success('退出成功')
  router.push('/login')
}

const goToBooking = () => {
  router.push('/booking')
}
</script>

<style scoped>
.admin-layout {
  min-height: 100vh;
}

.logo {
  padding: 16px;
  text-align: center;
  color: #1890ff;
  font-size: 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.logo h2 {
  margin: 0;
  color: #1890ff;
}

.admin-header {
  background: #fff;
  padding: 0 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.trigger {
  font-size: 18px;
  cursor: pointer;
  transition: color 0.3s;
}

.trigger:hover {
  color: #1890ff;
}

.header-right {
  display: flex;
  gap: 15px;
  align-items: center;
}

.admin-content {
  margin: 24px;
  padding: 24px;
  background: #fff;
  min-height: 280px;
  border-radius: 8px;
}
</style>
